package mwt.xml.xdbforms.schemalayer.types;

import javax.xml.XMLConstants;
import mwt.xml.xdbforms.dblayer.metadata.impl.ColumnMetaData;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;

/**
 *
 * Ritorna il tipo Float in xschema.
 *
 * @author Gianfranco Murador, Matteo Ferri, Cristian Castiglia
 */
public class XmlFloat extends XmlDecimal {

    public XmlFloat(Document doc) {
        super(doc);
    }

    XmlFloat() {
        
    }

    private void buildFragment(ColumnMetaData cmd) {

        Element xtype, restriction;

        typeName = cmd.getTypeName();
        fragment = doc.createDocumentFragment();
        xtype = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:simpleType");
        xtype.setAttribute("name", typeName);
        cmd.setXschemaTypeName(typeName);
        restriction = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:restriction");
        restriction.setAttribute("base", "xs:float");

        xtype.appendChild(restriction);
        fragment.appendChild(xtype);


    }

    @Override
    public DocumentFragment getSchemaType(ColumnMetaData cmd) {
        buildFragment(cmd);
        return fragment;
    }

    @Override
    public Object getXSchemaToJavaType(String baseType, String value) {
        Float f = Float.parseFloat(value);
        return f;
    }


}

